import config from '@/utils/config/index.js'
import request from '@/utils/request.js'
import { utilities, notice } from '@/utils/common.js'
// import { getTeamNow } from '@/api/business/shiftduty.js'
import { StartFlowNew, agreeFlow, rejectFlow } from '@/api/base/flow.js'
// import { getFlowKey, getSecond } from "@/pages/business/twotickets/workTicket/utils/constant.js"
// import { getFlowKey as getAtFlowKey, getSecond as getAtSecond } from "@/pages/business/twotickets/attachedTicket/utils/constant.js"

const uuid = require('uuid')

/**
 * 获取操作票类型
 */
export function otType() {
	return request.get({
		url: '/tickets/v3/api/ot-type/list'
	});
}

/**
 * 获取操作票类型
 */
export function otTypeByCond(params) {
	return request.post({
		url: '/tickets/v3/api/ot-type/getList',
		params,
		paramType: 'post',
		loading: false
	});
}

/**
 * 获取操作票两种人
 */
export function otPersonRole(params) {
	return request.get({
		url: '/tickets/v3/api/ot-person-role/page2',
		params
	});
}

/**
 * 获取操作票两种人
 */
export function otPersonRoleList(params) {
	return request.post({
		url: '/tickets/v3/api/ot-person-role/listByDO',
		params
	});
}

/**
 * 获取操作票两种人
 */
export function otPersonRoleListScene(params) {
	return request.post({
		url: '/tickets/v3/api/ot-person-role/listScene',
		params
	});
}

/**
 * 查询人员信息
 */
export function otPersonRoleById(userId) {
	const params = {
		userId
	}
	return request.get({
		url: '/tickets/v3/api/ot-person-role/findByUserId',
		params,
		loading: false
	});
}

/**
 * 获取操作票列表
 */
export function getTicketPage(params) {
	return request.post({
		url: '/tickets/v3/api/ot-operate-ticket/page',
		params,
		paramType: 'post'
	});
}

/**
 * 获取操作票待办列表
 */
export function getTicketPendingList(params) {
	return request.post({
		url: '/tickets/v3/api/ot-operate-ticket/list_app_pending',
		params,
		paramType: 'post'
	});
}

/**
 * 获取操作票全部详情
 */
export function getTicketDetailAll(otId) {
	const params = {
		otId
	}
	return request.get({
		url: '/tickets/v3/api/ot-operate-ticket/queryAll',
		params
	});
}

/**
 * 获取操作票详情
 */
export function getTicketDetail(params) {
	return request.get({
		url: '/tickets/v3/api/ot-operate-ticket/detail',
		params
	});
}

/**
 * 保存操作票详情
 */
export function saveTicketDetail(params) {
	return request.post({
		url: '/tickets/v3/api/ot-operate-ticket/save',
		params,
		paramType: 'post'
	});
}

/**
 * 保存操作票详情
 */
export function saveOtTicketDetail(params) {
	return request.post({
		url: '/tickets/v3/api/ot-operate-ticket/saveOrUpdate',
		params,
		paramType: 'post'
	});
}

/**
 * 生成操作票号
 */
export function generateTicketNo(otId) {
	const  params = {
		otId
	}
	return request.get({
		url: '/tickets/v3/api/ot-operate-ticket/generateNo',
		params
	});
}

/**
 * 获取典型操作票列表
 */
export function getStdOperationTicket(params) {
	return request.get({
		url: '/tickets/v3/api/ot-std-operateticket/page',
		params
	});
}

/**
 * 获取典型操作票详情
 */
export function getStdOperationTicketDetail(stdOtId) {
	const params = {
		stdOtId
	}
	return request.get({
		url: '/tickets/v3/api/ot-std-operateticket/queryAll',
		params
	});
}

/**
 * 获取危险点预控信息
 */
export function getDangerPage(params) {
	return request.get({
		url: '/tickets/v3/api/wt-hazard-control/page',
		params
	});
}

/**
 * 获取危险点预控信息
 */
export function getDangerList(params) {
	return request.get({
		url: '/tickets/v3/api/wt-hazard-control/list',
		params,
		loading: false
	});
}

/**
 * 删除危险点预控信息
 */
export function delHazardControl(objId) {
	const params = {
		objId
	}
	return request.get({
		url: '/tickets/v3/api/wt-hazard-control/deleteByObjId',
		params
	});
}

/**
 * 保存危险点预控信息
 */
export function saveHazardControl(params) {
	return request.post({
		url: '/tickets/v3/api/wt-hazard-control/addList',
		params,
		paramType: 'post'
	});
}

/**
 * 先删除再保存危险点预控信息
 */
export function removeAndSaveHazard(params) {
	return request.post({
		url: '/tickets/v3/api/wt-hazard-control/addListAndRemove',
		params,
		paramType: 'post'
	});
}

/**
 * 编辑危险点预控信息
 */
export function editHazardcControl(params) {
	return request.post({
		url: '/tickets/v3/api/wt-hazard-control/edit',
		params,
		paramType: 'post',
		loading: false
	});
}

/**
 * 获取危险源分类信息
 */
export function getHazardCategory(params) {
	return request.get({
		url: '/safety/v3/raHazards/tree',
		params
	});
}

/**
 * 获取危险源下的风险点
 */
export function getHazardEvaluation(params) {
	return request.get({
		url: '/safety/v3/raRiskControl/list',
		params
	});
}

/**
 * 获取风险点风险等级
 */
export function getHazardLevel() {
	return request.get({
		url: '/safety/v3/raRiskLevel/list'
	});
}

// 操作票详情中的操作项
export function getOperateItemPage(params) {
	return request.get({
		url: '/tickets/v3/api/ot-operate-item/page',
		params,
		loading: false
	});
}

// 操作票详情中的操作项
export function getOperateItemList(params) {
	return request.post({
		url: '/tickets/v3/api/ot-operate-item/listByDo',
		params,
		paramType: 'post',
		loading: false
	});
}

// 操作票详情中的操作项完成
export function finishOperateItem(params) {
	return request.post({
		url: '/tickets/v3/api/ot-operate-item/finish',
		params,
		loading: false
	});
}

// 操作票详情中的操作项删除
export function deleteOperateItem(params) {
	return request.get({
		url: '/tickets/v3/api/ot-operate-item/deleteByOtId',
		params,
		loading: false
	});
}

// 操作票详情中的操作项保存
export function saveOperateItem(params) {
	return request.post({
		url: '/tickets/v3/api/ot-operate-item/addList',
		params,
		paramType: "post",
		loading: false
	});
}

// 操作票详情中的操作项保存(先删除再保存)
export function saveOptItem(params) {
	return request.post({
		url: '/tickets/v3/api/ot-operate-item/saveOptItem',
		params,
		paramType: "post",
		loading: false
	});
}

// 操作票详情编辑
export function editOperateTicket(params) {
	return request.post({
		url: '/tickets/v3/api/ot-operate-ticket/edit',
		params,
		paramType: "post",
		loading: false
	});
}

// 沟通汇报列表
export function getCommunicatePage(params){
	return request.get({
		url: '/tickets/v3/api/wt-process-communication/listByObjId',
		params,
		loading: false
	});
}  

// 创建沟通汇报
export function createCommunicate(params){
	return request.post({
		url: '/tickets/v3/api/wt-process-communication/add',
		params,
		paramType: 'post'
	});
}

// 编辑沟通汇报
export function editCommunicate(params){
	return request.post({
		url: '/tickets/v3/api/wt-process-communication/edit',
		params,
		paramType: 'post'
	});
}

// 删除沟通汇报
export function deleteCommunicate(params){
	return request.get({
		url: '/tickets/v3/api/wt-process-communication/deleteGet',
		params,
	});
}  

/**
 * 获取工作票主票列表
 */
export function getWorkTicketList(params) {
	return request.post({
		url: '/tickets/v3/api/wt-work-ticket/page_app',
		params,
		paramType: 'post'
	});
}

/**
 * 获取工作票主票待办列表
 */
export function getWorkTicketPendingList(params) {
	return request.post({
		url: '/tickets/v3/api/wt-work-ticket/list_app_pending',
		params,
		paramType: 'post'
	});
}

/**
 * 获取工作票主票列表
 */
export function getWorkTicketPage(params) {
	return request.post({
		url: '/tickets/v3/api/wt-work-ticket/page',
		params
	});
}

/**
 * 获取工作票主票列表
 */
export function getWorkTicketPageLink(params) {
	return request.post({
		url: '/tickets/v3/api/wt-work-ticket/page_link',
		params
	});
}

/**
 * 获取工作票附票列表
 */
export function getAttachedTicketList(params) {
	return request.post({
		url: '/tickets/v3/api/wt-attached-ticket/page_app',
		params,
		paramType: 'post'
	});
}

/**
 * 获取工作票附票待办列表
 */
export function getAttachedTicketPendingList(params) {
	return request.post({
		url: '/tickets/v3/api/wt-attached-ticket/list_app_pending',
		params,
		paramType: 'post'
	});
}

/**
 * 分页查询附票
 */
export function getAttachedTicketWithRelation(params) {
	return request.post({
		url: '/tickets/v3/api/wt-attached-ticket/searchWithRelation',
		params,
		paramType: 'post'
	});
}

/**
 * 根据主票ID集合查询工作票信息
 */
export function listByWtIdList(params) {
	return request.post({
		url: '/tickets/v3/api/wt-attached-ticket/listByWtIdList',
		params,
		paramType: 'post'
	});
}

/**
 * 获取工作票关联信息
 */
export function getWorkTicketReList(wtId) {
	const params = {
		wtId
	}
	return request.get({
		url: '/tickets/v3/api/wt-at-re/getByWtId',
		params
	});
}

/**
 * 获取工作票类型
 */
export function getWorkTicketType() {
	return request.get({
		url: '/tickets/v3/api/wt-type/page?current=1&size=100',
	});
}

/**
 * 获取标准工作票列表
 */
export function getStdWorkTicket(params) {
	return request.post({
		url: '/tickets/v3/api/wt-std-workticket/page',
		params
	});
}

/**
 * 获取标准附票票列表
 */
export function getStdAttachedTicket(params) {
	return request.post({
		url: '/tickets/v3/api/wt-std-attached/pageByDo',
		params,
		paramType: 'post'
	});
}

/**
 * 获取标准工作票详情
 */
export function getStdWorkTicketDetail(stdWtId) {
	const params = {
		stdWtId
	}
	return request.get({
		url: '/tickets/v3/api/wt-std-workticket/detail',
		params
	});
}

/**
 * 获取标准工作票安措信息
 */
export function getStdSafeMeasurePage(stdWtId) {
	const params = {
		stdWtId,
		current: 1, 
		size: 500
	}
	return request.get({
		url: '/tickets/v3/api/wt-std-safemeasure/page',
		params
	});
}

/**
 * 获取标准工作票安措信息
 */
export function getStdSafeMeasureList(params) {
	return request.get({
		url: '/tickets/v3/api/wt-std-safemeasure/listByStdWtId',
		params
	});
}

/**
 * 获取标准票危险点预控信息
 */
export function getStdHazardControlPage(stdWtId) {
	const params = {
		objIds: stdWtId,
		current: 1, 
		size: 5000
	}
	return request.get({
		url: '/tickets/v3/api/wt-std-hazardcontrol/page',
		params
	});
}

/**
 * 获取标准票危险点预控信息
 */
export function getStdHazardControlList(params) {
	return request.get({
		url: '/tickets/v3/api/wt-std-hazardcontrol/list',
		params
	});
}

/**
 * 工作票主票详情
 */
export function getWorkticketDetail(wtId) {
	const params = {
		wtId
	}
	return request.get({
		url: '/tickets/v3/api/wt-work-ticket/detail',
		params
	});
}

/**
 * 工作票主票详情
 */
export function getWorkTicketDetail(wtId) {
	const params = {
		wtId
	}
	return request.get({
		url: '/tickets/v3/api/wt-work-ticket/getWithLink',
		params
	});
}

/**
 * 工作票主票详情
 */
export function getWorkTicketDetailById(wtId) {
	const params = {
		wtId
	}
	return request.get({
		url: '/tickets/v3/api/wt-work-ticket/getById',
		params
	});
}

/**
 * 通过关联ID查询工作票
 */
export function getWorkTicketByRelateId(params) {
	return request.post({
		url: '/tickets/v3/api/wt-work-ticket/listByDO',
		params
	});
}

/**
 * 工作票附票详情
 */
export function getAttachedTicketDetail(atId) {
	const params = {
		atId
	}
	return request.get({
		url: '/tickets/v3/api/wt-attached-ticket/detail',
		params
	});
}

/**
 * 保存工作票主票详情
 */
export function saveWorkticketDetail(params) {
	return request.post({
		url: '/tickets/v3/api/wt-work-ticket/saveOrUpdate',
		params,
		paramType: 'post'
	});
}

/**
 * 保存工作票附票详情
 */
export function saveAttachedTicketDetail(params) {
	return request.post({
		url: '/tickets/v3/api/wt-attached-ticket/saveOrUpdate',
		params,
		paramType: 'post'
	});
}

/**
 * 工作票执行信息
 */
export function getWtExecuteInfo(objId) {
	const params = {
		objId
	}
	return request.get({
		url: '/tickets/v3/api/wt-log-info/listByObjId',
		params,
		loading: false
	});
}

// 保存工作票执行信息
export function saveWtExecuteInfo(params){
	return request.post({
		url: '/tickets/v3/api/wt-log-info/uniqueSave',
		params,
		paramType: 'post'
	});
}

/**
 * 工作票安全措施类型 
 */
export function getSafemeasureTypebywtType(wtTypeId) {
	const params = {
		wtTypeId
	}
	return request.get({
		url: '/tickets/v3/api/wt-type-safemeasure/getByWtType',
		params
	});
}

/**
 * 工作票安全措施
 */
export function getSafemeasureByWtId(objId) {
	const params = {
		objId
	}
	return request.get({
		url: '/tickets/v3/api/wt-safe-measure/listByObjId',
		params
	});
}

/**
 * 删除安全措施
 */
export function delSafeMeasure(objId) {
	const params = {
		objId
	}
	return request.get({
		url: '/tickets/v3/api/wt-safe-measure/deleteByObjId',
		params
	});
}

/**
 * 保存安全措施
 */
export function saveSafeMeasure(params) {
	return request.post({
		url: '/tickets/v3/api/wt-safe-measure/addList',
		params,
		paramType: 'post'
	});
}

/**
 * 先删除再保存安全措施
 */
export function removeAndSaveSafe(params) {
	return request.post({
		url: '/tickets/v3/api/wt-safe-measure/addListAndRemove',
		params,
		paramType: 'post'
	});
}

/**
 * 编辑安全措施
 * 
 */
export function editSafe(params) {
	return request.post({
		url: '/tickets/v3/api/wt-safe-measure/edit',
		params,
		paramType: 'post',
		loading: false
	});
}

/**
 * 查询安全措施详细信息
 * 
 */
export function getSafe(smId) {
	return request.get({
		url: '/tickets/v3/api/wt-safe-measure/detail',
		params: { smId },
		loading: false
	});
}

/**
 * 查询所有三种人信息
 */
export function getRolePerson(params) {
	params.isOn = 1
	return request.post({
		url: '/tickets/v3/api/wt-person-role/listByDO',
		params,
		paramType: 'post'
	});
}

/**
 * 查询人员信息
 */
export function getRolePersonById(userId) {
	const params = {
		userId
	}
	return request.get({
		url: '/tickets/v3/api/wt-person-role/getByUserId',
		params,
		loading: false
	});
}

/**
 * 置空主票字段
 */
export function resetNull(params) {
	return request.get({
		url: '/tickets/v3/api/wt-work-ticket/resetNull',
		params
	});
}

/**
 * 置空附票字段
 */
export function resetAtNull(params) {
	return request.get({
		url: '/tickets/v3/api/wt-attached-ticket/resetNull',
		params
	});
}

/**
 * 生成工作票号
 */
export function generateNo(wtId) {
	const params = {
		wtId
	}
	return request.get({
		url: '/tickets/v3/api/wt-work-ticket/generateNo',
		params
	});
}

/**
 * 生成附票号
 */
export function generateAtNo(atId) {
	const params = {
		atId
	}
	return request.get({
		url: '/tickets/v3/api/wt-attached-ticket/generateNo',
		params
	});
}

/**
 * 工作票统计
 */
export function workTicketStatistics(params) {
	return request.post({
		url: '/tickets/v3/api/wt-work-ticket/statistics',
		params,
		paramType: 'post'
	});
}

/**
 * 操作票统计
 */
export function operateTicketStatistics(params) {
	return request.post({
		url: '/tickets/v3/api/ot-operate-ticket/statistics',
		params,
		paramType: 'post'
	});
}

/**
 *  获取服务器时间
 */
export function getTime(){
	return request.get({
		url: '/tickets/v3/api/time/get',
		loading: false
	})
}

// ********************流程审批通用方法*************************

/**
 * 逻辑补充数据
 */
export async function autoRun(form, curNode, isMain = true) {
	let needDos = curNode.needDo
				
	// 签发时间
	if(needDos.includes("auto_issueTime")){
		form.issueTime = utilities.getNowDateTime()
	}
	// 外包签发时间
	if(needDos.includes("auto_outIssueTime")){
		form.outIssueTime = utilities.getNowDateTime()
	}
	// 值长执行时间
	if(needDos.includes("auto_dutyUserTime")){
		form.dutyUserTime = utilities.getNowDateTime()
	}
	// 许可开工时间
	if(needDos.includes("auto_permitStartTime")){
		form.permitStartTime = utilities.getNowDateTime()
	}
	// 许可时间
	if(needDos.includes('auto_permitTime')){
		form.permitTime = utilities.getNowDateTime()
	}
	// 安措恢复时间
	if(needDos.includes("auto_safeRecoverTime")){
		form.safeRecoverTime = utilities.getNowDateTime()
	}
	// 安措执行时间
	if(needDos.includes("auto_executeTime")){
		form.executeTime = utilities.getNowDateTime()
	}
	// 工作终结时间
	if(needDos.includes("auto_workEndTime")){
		form.workEndTime = utilities.getNowDateTime()
	}
	// 附票-工作终结时间
	if(needDos.includes("auto_workFinishTime")){
		form.workFinishTime = utilities.getNowDateTime()
	}
	// 同意变更
	if(needDos.includes("auto_isAgreeChange")){
		form.isAgreeChange = "1"
	}
	// 同意延期
	if(needDos.includes("auto_isDelay")){
		form.isDelay = "1"
	}
	// 票号生成
	if(needDos.includes("auto_ticket_no")){
		if(isMain) {
			let result = await generateNo(form.wtId)
			form.wtNo = result.data
		} else {
			let result = await getWorkTicketDetailById(form.wtId)
			if(!!result.data.wtNo) {
				form.wtNo = result.data.wtNo
				let res = await generateAtNo(form.atId)
				form.atNo = res.data
			}else{
				notice.toast("主票尚未生成票号")
				throw new Error("主票尚未生成票号")
			}
		}
	}
	//抢修单值长批准开工时间
	if(needDos.includes("auto_approveStartTimeDuty")){
		form.approveStartTimeDuty = utilities.getNowDateTime()
	}
 
	// 当前值别
	if(needDos.includes("auto_team")){
		let { data: team } = await getTeamNow()
		form.teamNo   = team.teamNo
		form.teamName = team.teamName
	}
	
	return form
}

/**
 * 获取执行人(工作票)
 */
export function getExecutor(form, executorSign) {
	let needUserExecutor = {
		user_select: null,
		excetors   : [],
	}
				
	// 签发人
	if(executorSign === "issuer" || executorSign === "issue"){
		needUserExecutor.user_select = form.issuerId
		needUserExecutor.excetors    = [
			{
				id       : form.issuerId,
				name     : form.issuerName,
				type     : "employee",
				groupType: "",
			},
		]
	}
	
	// 外包签发人
	else if(executorSign === "issuer_out"){
		needUserExecutor.user_select = form.outIssuerId
		needUserExecutor.excetors    = [
			{
				id       : form.outIssuerId,
				name     : form.outIssuerName,
				type     : "employee",
				groupType: "",
			},
		]
	}
	
	//联系人
	else if(executorSign === "contact"){
		needUserExecutor.user_select = form.contactorId
		needUserExecutor.excetors    = [
			{
				id       : form.contactorId,
				name     : form.contactorName,
				type     : "employee",
				groupType: "",
			},
		]
	}
	
	// 负责人
	else if(executorSign === "manager"){
		needUserExecutor.user_select = form.managerId
		needUserExecutor.excetors    = [
			{
				id       : form.managerId,
				name     : form.managerName,
				type     : "employee",
				groupType: "",
			},
		]
	}
				
	// 特殊负责人:	1.如果有变更人,则使用变更人.	2.没有则使用负责人
	else if(executorSign === "manager_special"){
		if(form.isAgreeChange === "1"){
			needUserExecutor.user_select = form.changeUserId
			needUserExecutor.excetors    = [
				{
					id       : form.changeUserId,
					name     : form.changeUserName,
					type     : "employee",
					groupType: "",
				},
			]
		}else{
			needUserExecutor.user_select = form.managerId
			needUserExecutor.excetors    = [
				{
					id       : form.managerId,
					name     : form.managerName,
					type     : "employee",
					groupType: "",
				},
			]
		}
	}
				
	// 变更人
	else if(executorSign === "changeUser"){
		needUserExecutor.user_select = form.changeUserId
		needUserExecutor.excetors    = [
			{
				id       : form.changeUserId,
				name     : form.changeUserName,
				type     : "employee",
				groupType: "",
			},
		]
	}
				
	// 许可人
	else if(executorSign === "permitor"){
		needUserExecutor.user_select = form.permitorId
		needUserExecutor.excetors    = [
			{
				id       : form.permitorId,
				name     : form.permitorName,
				type     : "employee",
				groupType: "",
			},
		]
	}
				
	// 结票许可人
	else if(executorSign === "finishPermit"){
		needUserExecutor.user_select = form.finishPermitId
		needUserExecutor.excetors    = [
			{
				id       : form.finishPermitId,
				name     : form.finishPermitName,
				type     : "employee",
				groupType: "",
			},
		]
	}
				
	// 延期许可人
	else if(executorSign === "delayUser"){
		needUserExecutor.user_select = form.delayUserId
		needUserExecutor.excetors    = [
			{
				id       : form.delayUserId,
				name     : form.delayUserName,
				type     : "employee",
				groupType: "",
			},
		]
	}
				
	// 值长
	else if(executorSign === "duty"){
		needUserExecutor.user_select = form.dutyUserId
		needUserExecutor.excetors    = [
			{
				id       : form.dutyUserId,
				name     : form.dutyUserName,
				type     : "employee",
				groupType: "",
			},
		]
	}
				
	// 延期审批值长
	else if(executorSign === "dutyDelay"){
		needUserExecutor.user_select = form.dutyUserDelayId
		needUserExecutor.excetors    = [
			{
				id       : form.dutyUserDelayId,
				name     : form.dutyUserDelayName,
				type     : "employee",
				groupType: "",
			},
		]
	}
				
	// 结票审批值长
	else if(executorSign === "dutyFinish"){
		needUserExecutor.user_select = form.dutyUserFinishId
		needUserExecutor.excetors    = [
			{
				id       : form.dutyUserFinishId,
				name     : form.dutyUserFinishName,
				type     : "employee",
				groupType: "",
			},
		]
	}
	
	// 附票-签发人
	else if(executorSign === "signer" || executorSign === "sign_signer"){
		needUserExecutor.user_select = form.issuerId
		needUserExecutor.excetors    = [
			{
				id       : form.issuerId,
				name     : form.issuerName,
				type     : "employee",
				groupType: "",
			},
		]
	}
	
	// 特殊作业部门负责人
	else if(executorSign === "specialWorkUser"){
		needUserExecutor.user_select = form.specialWorkUserId
		needUserExecutor.excetors    = [
			{
				id       : form.specialWorkUserId,
				name     : form.specialWorkUserName,
				type     : "employee",
				groupType: "",
			},
		]
	}
	
	// 安监专责人员
	else if(executorSign === "safetySpecificUser"){
		needUserExecutor.user_select = form.safetySpecificUserId
		needUserExecutor.excetors    = [
			{
				id       : form.safetySpecificUserId,
				name     : form.safetySpecificUserName,
				type     : "employee",
				groupType: "",
			},
		]
	}
	
	// 保卫消防部门负责人
	else if(executorSign === "firemanUser"){
		needUserExecutor.user_select = form.firemanUserId
		needUserExecutor.excetors    = [
			{
				id       : form.firemanUserId,
				name     : form.firemanUserName,
				type     : "employee",
				groupType: "",
			},
		]
	}
	
	// 动火部门负责人
	else if(executorSign === "fireOpenUser"){
		needUserExecutor.user_select = form.fireOpenUserId
		needUserExecutor.excetors    = [
			{
				id       : form.fireOpenUserId,
				name     : form.fireOpenUserName,
				type     : "employee",
				groupType: "",
			},
		]
	}
	
	// 安监部门负责人
	else if(executorSign === "safesupUser"){
		needUserExecutor.user_select = form.safesupUserId
		needUserExecutor.excetors    = [
			{
				id       : form.safesupUserId,
				name     : form.safesupUserName,
				type     : "employee",
				groupType: "",
			},
		]
	}
	
	// 分管领导
	else if(executorSign === "branchUser"){
		needUserExecutor.user_select = form.branchUserId
		needUserExecutor.excetors    = [
			{
				id       : form.branchUserId,
				name     : form.branchUserName,
				type     : "employee",
				groupType: "",
			},
		]
	}
	
	// 安措执行人
	else if(executorSign === "safeUser"){
		needUserExecutor.user_select = form.safeUserId
		needUserExecutor.excetors    = [
			{
				id       : form.safeUserId,
				name     : form.safeUserName,
				type     : "employee",
				groupType: "",
			},
		]
	}
	
	// 消防监护人
	else if(executorSign === "guarder"){
		needUserExecutor.user_select = form.guarderId
		needUserExecutor.excetors    = [
			{
				id       : form.guarderId,
				name     : form.guarderName,
				type     : "employee",
				groupType: "",
			},
		]
	}
	
	// 结票许可人
	else if(executorSign === "finishPermitor"){
		needUserExecutor.user_select = form.finishPermitUserId
		needUserExecutor.excetors    = [
			{
				id       : form.finishPermitUserId,
				name     : form.finishPermitUserName,
				type     : "employee",
				groupType: "",
			},
		]
	}
	
	return needUserExecutor
}

/**
 * 获取执行人(操作票)
 */
export function getOtExecutor(form, executorSign) {
	let excetors = []
	
	// 监护人
	if(executorSign === "guarder" || executorSign === "check_guarder"){
		excetors = [
			{ 
				id: form.guarder1Id, 
				name: form.guarder1Name, 
				type: "employee", 
				groupType: "" ,
			},
		]
	}
	
	// 值长
	else if(executorSign === "duty"){
		excetors = [
			{ 
				id: form.dutyLeaderId, 
				name: form.dutyLeaderName, 
				type: "employee", 
				groupType: "" ,
			},
		]
	}
	
	// 操作人
	else if(executorSign === "operator"){
		excetors = [
			{ 
				id: form.operator2Id, 
				name: form.operator2Name, 
				type: "employee", 
				groupType: "" ,
			},
			{ 
				id: form.operator1Id, 
				name: form.operator1Name, 
				type: "employee", 
				groupType: "" ,
			},
			{
				id: form.guarder2Id, 
				name: form.guarder2Name, 
				type: "employee", 
				groupType: "" ,
			},
			{ 
				id: form.guarder1Id, 
				name: form.guarder1Name, 
				type: "employee", 
				groupType: "" ,
			},
		]
	}
	
	return excetors
}

/**
 * 流程-启动
 */
export async function startFlow(needUserExecutor, formData, curNode, isMain = true) {
	let { excetors, user_select } = needUserExecutor
	// 配置启动参数
	const queryParams = {
		formKey    : "twoTicket",
		variableMap: {
			USER_SELECT: user_select,
		},
		nodeUsers  : JSON.stringify([
			{
				nodeId   : curNode.buttons.agree.arrow,
				executors: excetors,
			},
		]),
	}
	if(isMain) {
		queryParams.defKey = getFlowKey(formData.wtTypeNo)
		queryParams.ids = formData.wtId
	} else {
		queryParams.defKey = getAtFlowKey(formData.wtTypeNo)
		queryParams.ids = formData.atId
	}
				
	// 启动流程
	await StartFlowNew(queryParams)
	// let res = await StartFlowNew(queryParams) 
	// if(res.state === 200) {
	// 	if(isMain) {
	// 		saveWorkticketDetail({
	// 			wtId: formData.wtId,
	// 			state: getSecond(formData.wtTypeNo)
	// 		})
	// 	} else {
	// 		saveAttachedTicketDetail({
	// 			atId: formData.atId,
	// 			state: getAtSecond(formData.wtTypeNo)
	// 		})
	// 	}
	// }
}

/**
 * 流程-同意
 */
export async function flowAgree(needUserExecutor, form, flowButtonNow, taskId, opinion, isMain = true) {
	let { excetors, user_select } = needUserExecutor
	
	// 构造参数
	let approveRequest = {
		opinion    : opinion,
		destination: "",
		taskId     : taskId,
		variableMap: {
			USER_SELECT: user_select,
			exchange   : flowButtonNow.no,
		},
		nodeUsers  : JSON.stringify([
			{
				nodeId   : flowButtonNow.arrow,
				executors: excetors,
			},
		]),
		// 事务：消息使用
		transFlag: true
	}
				
	// 发起请求
	await agreeFlow(approveRequest)
	// let res = await agreeFlow(approveRequest) 
	// if(res.state === 200){
	// 	// 更新状态
	// 	form.state = flowButtonNow.arrow
	// 	if(isMain) {
	// 		await saveWorkticketDetail(form)
	// 	} else {
	// 		await saveAttachedTicketDetail(form)
	// 	}
	// }
}

/**
 * 流程-不同意
 */
export async function commitReject(sourceType, needUserExecutor, form, flowButtonNow, curNode, taskId, opinion, isMain = true) {
	// 构造参数
	let { user_select } = needUserExecutor
	
	// 驳回请求参数
	let previousRequest = {
		taskId      : taskId,
		backHandMode: "normal",
		destination : flowButtonNow.arrow,
		opinion     : opinion,
		// 事务：消息使用
		transFlag: true
	}
	
	let rejectResult = await rejectFlow(previousRequest)
	let success = rejectResult.state === 200
	if(success){
		// 上一级审批流程状态
	// 	form.state = flowButtonNow.arrow
	
	// 	if(isMain) {
	// 		await saveWorkticketDetail(form)
	// 	} else {
	// 		await saveAttachedTicketDetail(form)
	// 	}
		
		let ticketId = ""
		if(isMain) {
			ticketId = form.wtId
		} else {
			ticketId = form.atId
		}
		//needDo需要做的事情相关处理
		await autoRejectRun(ticketId, curNode, isMain)
		await autoDelayRun(ticketId, curNode, isMain)
	}
	
	utilities.backQuick(sourceType)
}

/**
 * 特别置空变更信息
 */
export async function autoRejectRun(ticketId, curNode, isMain = true){
	let needDos = curNode.needDo
	//变更负责人,不同意清除相关信息
	if(needDos.includes("clear_manager_info")){
		let param = {
			fields: [
				"change_user_id",
				"change_user_name",
				"change_reason",
				"change_time",
			]
		}
		if(isMain) {
			param.wtId = ticketId
			await resetNull(param)
		} else {
			param.atId = ticketId
			await resetAtNull(param)
		}
	}
}

/**
 * 特别置空延期信息
 */
export async function autoDelayRun(ticketId, curNode, isMain = true){
	let needDos = curNode.needDo
	//延期许可人,不同意清除相关信息
	if(needDos.includes("clear_delay_info")){
		let param = {
			fields: [
				"delay_user_id",
				"delay_user_name",
				"delay_reason",
				"delay_time",
			]
		}
		if(isMain) {
			param.wtId = ticketId
			await resetNull(param)
		} else {
			param.atId = ticketId
			await resetAtNull(param)
		}
	}
}

/**
 * 保存安措信息
 */
export async function saveSafe(wtId, safeMeasureList){
	safeMeasureList.forEach(safeType => {
		safeType.smContentList.forEach((safe, index) => {
			safe.objId  = wtId
			safe.sortNo = index
		})
	})
	
	let safeList2Save = []
	safeMeasureList.forEach(safeType => {
		safeList2Save.push(...safeType.smContentList)
	})
	
	let params = {
		objId: wtId,
		wtSafeMeasurePoList: safeList2Save
	}
	await removeAndSaveSafe(params)
}

/**
 * 保存危险点信息
 */
export async function saveDanger(wtId, wtTypeNo, dangerList){
	dangerList.forEach((item, index) => {
		item.objId = wtId
		item.objNo = wtTypeNo
		item.sortNo = index
	})
	
	let parmas = {
		objId: wtId,
		wtHazardControlPoList: dangerList
	}
	await removeAndSaveHazard(parmas)
}

/**
 * 总人数，默认1，代表（外包）工作负责人
 */
 function getCount(list,userId){
  let count =1;
  count=list.length+1
  if(list&&list.length>0){
    let user = list.find(item=>item.userId==userId)
    if(user){
      count=list.length
    }
  }
  return count
}
/**
 * 获取选人
 */
export function recivePerson(type, user, form){
	if(type == 'manager') { // 负责人
		form.managerId = user.userId
		form.managerName = user.userName
	} else if(type == 'contactor') { // 联系人
		form.contactorId = user.userId
		form.contactorName = user.userName
		form.contactorDeptId = user.groupID
		form.contactorDeptName ="";
		let arr= user.orgName&&user.orgName.length>0?user.orgName.split("."):[];
		if (arr && arr.length > 1) {
			form.contactorDeptName = arr[arr.length - 2];// 责任主体'
		}
		form.contactorPhone = user.mobile
	} else if(type == 'member') { // 工作成员
		let userIds = []
		let userNames = []
		user.forEach(item=>{
			if(!userIds.includes(item.userId)) {
				userIds.push(item.userId)
			}
			if(!userNames.includes(item.userName)) {
				userNames.push(item.userName)
			}
		})
		form.memberIds = userIds.join()
		form.memberNames = userNames.join()
		form.oprOperatorIds = userIds[0]
		form.oprOperatorNames = userNames[0]
		form.memberNumber = getCount(user, form.managerId)
		form.memberCount = getCount(user, form.managerId)
	} else if(type == 'memberFire') { // 工作成员
		let userIds = []
		let userNames = []
		user.forEach(item=>{
			if(!userIds.includes(item.userId)) {
				userIds.push(item.userId)
			}
			if(!userNames.includes(item.userName)) {
				userNames.push(item.userName)
			}
		})
		form.memberIds = userIds.join()
		form.memberNames = userNames.join()
		form.memberNumber = getCount(user, form.managerId)
		form.memberCount = getCount(user, form.managerId)
	} else if(type == 'oprOperator') { // 运行安措执行人
		form.oprOperatorIds = user.userId
		form.oprOperatorNames = user.userName
	} else if(type == 'mtnOperator') { // 检修安措执行人
		form.mtnOperatorIds = user.userId
		form.mtnOperatorNames = user.userName
	} else if(type == 'issuer' || type == 'issuerDH') { // 签发人、动火签发人
		form.issuerId = user.userId
		form.issuerName = user.userName
	} else if(type == 'outIssuer' || type == 'outIssuerDH') { // 外包签发人、动火外包签发人
		form.outIssuerId = user.userId
		form.outIssuerName = user.userName
	} else if(type == 'permit') { // 许可人
		form.permitorId = user.userId
		form.permitorName = user.userName
		form.oprOperatorIds = user.userId
		form.oprOperatorNames = user.userName
	} else if(type == 'receiver') { // 接票人
		form.receiverId = user.userId
		form.receiverName = user.userName
	} else if(type == 'delay') {//延期
		form.delayUserId = user.userId
		form.delayUserName = user.userName
	} else if(type == 'change') {//工作负责人变更
		form.changeUserId = user.userId
		form.changeUserName = user.userName
	} else if(type == 'jpPermit') {//结票许可人
		form.finishPermitId = user.userId
		form.finishPermitName = user.userName
	} else if(type == 'duty') {//值长
		form.dutyUserId = user.userId
		form.dutyUserName = user.userName
	} else if(type == 'delayDuty') {//延期值长
		form.dutyUserDelayId = user.userId
		form.dutyUserDelayName = user.userName
	}  else if(type == 'finishDuty') {//结票审批值长
		form.dutyUserFinishId = user.userId
		form.dutyUserFinishName = user.userName
	} else if(type == 'check') {
		form.tstOperatorIds = user.userId
		form.tstOperatorNames = user.userName
	} else if(type == 'tsPermit') {
		form.finishPermitUserId = user.userId
		form.finishPermitUserName = user.userName
	} else if(type == 'jkOperator') { // 操作票-集控操作人
		form.operator1Id = user.userId
		form.operator1Name = user.userName
		form.operator1Dept = user.deptName
	} else if(type == 'jkGuarder') { // 操作票-集控监护人
		form.guarder1Id = user.userId
		form.guarder1Name = user.userName
	} else if(type == 'xcOperator') { // 操作票-现场操作人
		form.operator2Id = user.userId
		form.operator2Name = user.userName
		form.operator2Dept = user.deptName
	} else if(type == 'xcGuarder') { // 操作票-现场监护人
		form.guarder2Id = user.userId
		form.guarder2Name = user.userName
	} else if(type == 'cmder') { // 操作票-发令人
		form.cmderId = user.userId
		form.cmderName = user.userName
	} else if(type == 'cmdAcceptor') { // 操作票-受令人
		form.cmdAcceptorId = user.userId
		form.cmdAcceptorName = user.userName
	} else if(type == 'operator') { // 附票-动火执行人
		form.operatorIds = user.userId
		form.operatorNames = user.userName
	} else if(type == 'operatorDH') { // 附票-动火执行人
		let userIds = []
		let userNames = []
		user.forEach(item=>{
			if(!userIds.includes(item.userId)) {
				userIds.push(item.userId)
			}
			if(!userNames.includes(item.userName)) {
				userNames.push(item.userName)
			}
		})
		form.operatorIds = userIds.join()
		form.operatorNames = userNames.join()
	} else if(type == 'permitDH') { // 附票-许可人
		form.permitorId = user.userId
		form.permitorName = user.userName
		form.safeUserId = user.userId
		form.safeUserName = user.userName
	} else if(type == 'safeUser') { // 附票-运行安措执行人
		form.safeUserId = user.userId
		form.safeUserName = user.userName
	} else if(type == 'firemanUser') { // 附票-保卫消防部门负责人
		form.firemanUserId = user.userId
		form.firemanUserName = user.userName
	} else if(type == 'fireOpenUser') { // 附票-动火部门负责人
		form.fireOpenUserId = user.userId
		form.fireOpenUserName = user.userName
	} else if(type == 'guarder' || type == 'guarderDH') { // 附票-消防监护人、动火监护人
		form.guarderId = user.userId
		form.guarderName = user.userName
	} else if(type == 'safesupUser') { // 附票-安监部门负责人
		form.safesupUserId = user.userId
		form.safesupUserName = user.userName
	} else if(type == 'branchUser') { // 附票-分管领导
		form.branchUserId = user.userId
		form.branchUserName = user.userName
	} else if(type == 'tstOperator') { // 附票-检测人
		form.tstOperatorIds = user.userId
		form.tstOperatorNames = user.userName
	} else if(type == 'specialWorkUser') { // 附票-特殊作业部门负责人
		form.specialWorkUserId = user.userId
		form.specialWorkUserName = user.userName
	} else if(type == 'safetySpecificUser') { // 附票-安监专责人员
		form.safetySpecificUserId = user.userId
		form.safetySpecificUserName = user.userName
	} else if(type == 'deptUser') { // 附票-部门管理人员
		form.deptUserId = user.userId
		form.deptUserName = user.userName
	} 
	return form
}

/**
 * 校验选人
 */
export function validatePerson(type, user, form){
	let flag = true
	if(type == 'issuer') {
		if(user.userId == form.managerId) {
			notice.toast("不能与负责人相同")
			flag = false
		} else if(user.userId == form.outIssuerId) {
			notice.toast("不能与外包签发人相同")
			flag = false
		} else if(user.userId == form.permitorId) {
			notice.toast("不能与许可人相同")
			flag = false
		}
	} else if(type == 'outIssuer') {
		if(user.userId == form.managerId) {
			notice.toast("不能与负责人相同")
			flag = false
		} else if(user.userId == form.issuerId) {
			notice.toast("不能与签发人相同")
			flag = false
		} else if(user.userId == form.permitorId) {
			notice.toast("不能与许可人相同")
			flag = false
		}
	} else if(type == 'delay' || type == 'permit' || type == 'tsPermit'|| type == 'jpPermit') {
		if(user.userId == form.managerId) {
			notice.toast("不能与负责人相同")
			flag = false
		} else if(user.userId == form.outIssuerId) {
			notice.toast("不能与外包签发人相同")
			flag = false
		} else if(user.userId == form.issuerId) {
			notice.toast("不能与签发人相同")
			flag = false
		} else if(user.userId == form.changeUserId) {
			notice.toast("不能与负责人相同")
			flag = false
		}
	} else if(type == 'change') {
		if(user.userId == form.managerId) {
			notice.toast("不能与负责人相同")
			flag = false
		} else if(user.userId == form.outIssuerId) {
			notice.toast("不能与外包签发人相同")
			flag = false
		} else if(user.userId == form.issuerId) {
			notice.toast("不能与签发人相同")
			flag = false
		} else if(user.userId == form.permitorId) {
			notice.toast("不能与许可人相同")
			flag = false
		} else if(user.userId == form.delayUserId) {
			notice.toast("不能与延期许可人相同")
			flag = false
		}
	} else if(type == 'jkOperator' || type == 'jkGuarder' || type == 'xcOperator' || type == 'xcGuarder') {
		if(user.userId == form.operator1Id) {
			notice.toast("用户已参与")
			flag = false
		} else if(user.userId == form.guarder1Id) {
			notice.toast("用户已参与")
			flag = false
		} else if(user.userId == form.operator2Id) {
			notice.toast("用户已参与")
			flag = false
		} else if(user.userId == form.guarder2Id) {
			notice.toast("用户已参与")
			flag = false
		}
	}
	return flag
}

// 物料-列表查询
export function getDataMaterialsApi(params) {
	return request.get({
		url: '/tickets/v3/api/woMaterial/find/list',
		params
	});
}

// 物料-增加物料(批量)
export function saveDataMaterialsApi(params) {
	return request.post({
		url: '/tickets/v3/api/woMaterial/save/list',
		params,
		paramType: 'post'
	});
}

// 物料-修改物料(批量)
export function updateDataMaterialsApi(params) {
	return request.post({
		url: '/tickets/v3/api/woMaterial/update/list',
		params,
		paramType: 'post'
	});
}

// 物料-根据领料退料更新
export function updateByMaterialsApi(params) {
	return request.post({
		url: '/tickets/v3/api/woMaterial/updateByMaterial',
		params,
		paramType: 'post'
	});
}

// 工作票附加信息-保存或更新
export function saveAppendInfo(params) {
	return request.post({
		url: '/tickets/v3/api/wt-append-info/saveOrUpdate',
		params,
		paramType: 'post'
	});
}

// 工作票附加信息-根据对象查询数据
export function getAppendInfo(params) {
	return request.post({
		url: '/tickets/v3/api/wt-append-info/listByDO',
		params,
		paramType: 'post',
		loading: false
	});
}

// 工作票附加信息-安措解除更新数据
export async function updateByRelieve(params) {
	let result = await uni.request({
		url: config.baseUrl + '/tickets/v3/api/wt-append-info/updateByRelieve',
		data: params,
		method: 'POST',
		header: {
			'X-Authorization-access_token': uni.getStorageSync("_app_token")
		}
	})
	if(result[1]) {
		return result[1].data
	}
}

// 查询二维码信息
export function getQrcodeDetail(params) {
	return request.get({
		url: '/tickets/v3/api/cpis_qrcode_type/getDetail',
		params,
		loading: false
	});
}

// 附加文档详细信息
export function getAddDocDetail(params) {
	return request.get({
		url: '/tickets/v3/api/wt-ad-type/detail',
		params,
		loading: false
	});
}

// 附加文档全部类型
export function getAddDocList() {
	return request.get({
		url: '/tickets/v3/api/wt-ad-type/list',
		loading: false
	});
}

// 创建变更人员记录
export function addPersonChange(params) {
	return request.post({
		url: '/tickets/v3/api/wt-person-change/add',
		params,
		paramType: 'post',
		loading: false
	});
}

// 创建允许试运记录
export function addCommissioning(params) {
	return request.post({
		url: '/tickets/v3/api/wt-tr-rw/add',
		params,
		paramType: 'post',
		loading: false
	});
}

// 创建允许恢复工作记录
export function updateCommissioning(params) {
	return request.post({
		url: '/tickets/v3/api/wt-tr-rw/saveOrUpdate',
		params,
		paramType: 'post',
		loading: false
	});
}

// 查询最新的试运记录
export function getCommissioning(wtId) {
	return request.get({
		url: '/tickets/v3/api/wt-tr-rw/getByWtId',
		params: { wtId },
		loading: false
	});
}

// 检查当前负责人名下是否存在未办结的票
export function checkManagerHasTickets(managerId) {
	return request.get({
		url: '/tickets/v3/api/wt-work-ticket/checkManagerHasTickets',
		params: { managerId },
		loading: false
	});
}

// 根据票类型获取测量参数信息
export function getMpByWtTypeId(wtTypeId) {
	return request.get({
		url: `/tickets/v3/api/wtTypeMp/getByWtTypeId/${wtTypeId}`,
		loading: false
	});
}

// 根据票id获取测量参数登记信息
export function getMpReg(watId) {
	return request.get({
		url: `/tickets/v3/api/wtMpReg/getByWatId/${watId}`,
		loading: false
	});
}


// 保存测量参数登记信息
export function saveMpReg(params) {
	return request.post({
		url: '/tickets/v3/api/wtMpReg/save',
		params,
		paramType: 'post',
		loading: false
	});
}

// 根据票id获取参数测量批次信息
export function getMpMeasBatch(watId) {
	return request.get({
		url: `/tickets/v3/api/wtMpMeasBatch/getByWatId/${watId}`,
		loading: false
	});
}

// 保存参数测量批次信息
export function saveMpMeasBatch(params) {
	return request.post({
		url: '/tickets/v3/api/wtMpMeasBatch/save',
		params,
		paramType: 'post',
		loading: false
	});
}

// 删除参数测量批次信息
export function deleteMpMeasBatch(mpBatchId) {
	return request.post({
		url: `/tickets/v3/api/wtMpMeasBatch/delete/${mpBatchId}`,
		paramType: 'post',
		loading: false
	});
}

// 创建间断记录
export function saveInterrupt(params) {
	return request.post({
		url: '/tickets/v3/api/wt-interrupt/add',
		params,
		paramType: 'post',
		loading: false
	});
}

// 获取隐蔽设施项目
export function getFacsItemList() {
	return request.get({
		url: '/tickets/v3/api/wt-cfacs-item/list',
		loading: false
	});
}


// 获取隐蔽设施记录
export function getFacsRecordList(atId) {
	return request.get({
		url: '/tickets/v3/api/wt-cfacs-record/listByAtId',
		params: { atId },
		loading: false
	});
}

// 保存隐蔽设施记录
export function saveFacs(params) {
	return request.post({
		url: '/tickets/v3/api/wt-cfacs-record/addList',
		params,
		paramType: 'post',
		loading: false
	});
}

// 创建工作票特殊操作备注记录
export function saveOperateRemark(params) {
	return request.post({
		url: '/tickets/v3/api/wt-operate-remark/add',
		params,
		paramType: 'post',
		loading: false
	});
}

// 查询最新的工作票特殊操作备注
export function getOperateRemark(params) {
	return request.get({
		url: '/tickets/v3/api/wt-operate-remark/getByWtId',
		params,
		loading: false
	});
}

// 创建或更新工作票特殊操作备注记录
export function updateOperateRemark(params) {
	return request.post({
		url: '/tickets/v3/api/wt-operate-remark/saveOrUpdate',
		params,
		paramType: 'post',
		loading: false
	});
}

// 获取全部两票附加附件
export function getAttachFileList(wtId) {
	return request.get({
		url: '/tickets/v3/api/tt-attach-file/listByWtId',
		params: { wtId },
		loading: false
	});
}

// 创建和更新两票附加附件
export function updateAttachFile(params) {
	return request.post({
		url: '/tickets/v3/api/tt-attach-file/saveOrUpdate',
		params,
		paramType: 'post',
		loading: false
	});
}

// 创建工作票延期申请
export function addExtension(params) {
	return request.post({
		url: '/tickets/v3/api/wt-extension/add',
		params,
		paramType: 'post',
		loading: false
	});
}

// 创建或更新工作票延期申请
export function updateExtension(params) {
	return request.post({
		url: '/tickets/v3/api/wt-extension/saveOrUpdate',
		params,
		paramType: 'post',
		loading: false
	});
}

// 查询最新的工作票延期申请
export function getExtension(wtId) {
	return request.get({
		url: '/tickets/v3/api/wt-extension/getByWtId',
		params: { wtId },
		loading: false
	});
}

// 获取全部工作票类型页面地址
export function getWorkTicketTypePage() {
	return request.get({
		url: '/tickets/v3/api/wt-type-page/list',
		loading: false
	});
}

// 获取工作票类型页面地址
export function getWtTypePageById(wtTypeId) {
	return request.get({
		url: '/tickets/v3/api/wt-type-page/getWtTypeById',
		params: { wtTypeId },
		loading: false
	});
}

// 获取统计分析配置
export function getStateMappingList(params) {
	return request.post({
		url: '/tickets/v3/api/tt-state-mapping/list',
		params,
		paramType: 'post',
		loading: false
	});
}

// 创建IOT消息授权
export function iotBizGrant(params) {
	return request.post({
		url: '/tickets/v3/api/iot-biz-grant/add',
		params,
		paramType: 'post',
		loading: false
	});
}

// 订阅IOT告警
export function subElecFenceAlarm(params) {
	return request.post({
		url: '/tickets/v3/api/iot-biz-grant/subElecFenceAlarm',
		params,
		paramType: 'post',
		loading: false
	});
}